package com.pzh.guli.service.edu.controller.admin;


import com.pzh.guli.service.base.result.Result;
import com.pzh.guli.service.edu.feign.VodService;
import com.pzh.guli.service.edu.pojo.Video;
import com.pzh.guli.service.edu.service.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author xzh
 * @since 2022-05-11
 */
@RestController
@RequestMapping("admin/edu/video")
public class VideoController {
    @Autowired
    private IVideoService videoService;
    @Autowired
    private VodService vodService;
    //新增video
    @PostMapping("save")
    public Result save(@RequestBody Video video){
        boolean save = videoService.save(video);
        if (save){
            return Result.ok().message("新增课时成功");
        }
        return Result.error().message("新增课时失败");
    }
    //更新video
    @PutMapping("update")
    public Result update(@RequestBody Video video){
        boolean update = videoService.updateById(video);
        if (update){
            return Result.ok().message("更新video成功");
        }
        return Result.error().message("更新video失败");
    }
    //查询video 根据id
    @GetMapping("/{id}")
    public Result selectVideoById(@PathVariable String id){
        Video video = videoService.getById(id);
        return Result.ok().data("item",video);
    }
    //t通过id 删除一个video
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable String id){
        //远程删除云服务Video
        //根据video id 查 出 云视频id
        String videoSourceId=videoService.selectSourceIdByVideoId(id);
        vodService.removeOneVideoById(videoSourceId);
        boolean removeById = videoService.removeById(id);
        if (removeById){
            return Result.ok().message("删除成功");
        }
        return Result.error().message("数据不存在，删除失败!");
    }
}

